package org.gilgamesh.stool.search.es;

import org.gilgamesh.stool.search.SearchResponse;
import org.gilgamesh.stool.search.constant.ResponseStatus;
import org.gilgamesh.stool.search.es.result.Result;

import java.util.Map;

/**
 * ES查询的响应
 *
 * @author Gilgamesh
 * @since 2021-08-20
 **/
public class ESSearchResponse implements SearchResponse {
    /**
    * 结果数量
    **/
    private int total;

    /**
    * 结果,Key是request中设置的
    **/
    private ResponseStatus status;

    /**
    * 返回结果，k是Request
    **/
    private Map<String, Result> resultMap;

    @Override
    public Integer total() {
        return total;
    }

    @Override
    public ESSearchResponse total(Integer total) {
        this.total = total;
        if(total>0){
            status = ResponseStatus.SUCCESS;
        }else{
            status = ResponseStatus.FAILED;
        }
        return this;
    }

    @Override
    public ResponseStatus status() {
        return status;
    }

    @Override
    public ESSearchResponse status(ResponseStatus status) {
        this.status = status;
        return this;
    }

    public Map<String,Result> resultMap(){
        return this.resultMap;
    }

    public ESSearchResponse resultMap(Map<String,Result> resultMap){
        this.resultMap = resultMap;
        return this;
    }
}
